import { UserProfilesAPI } from "@/request/api"

export default {
    namespaced: true,
    state: {
        // 数据
        userInfo: {
            nickName: '彭于晏',
            coin: 10,
            headImg: require('../../assets/img/service.848ec511.png')
        },
        cartTotal: 10
    },
    mutations: {
        // 修改显示隐藏的方法
        // vue语法规定 修改state内容只能在方法里面
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        initUserInfo(state) {
            state.userInfo = {
                nickName: '彭于晏',
                coin: 10,
                headImg: require('../../assets/img/service.848ec511.png')
            },
                state.cartTotal = 10
        }
    },
    // 发送请求修改用户信息
    actions: {
        async asyncChangeUserInfo({ commit }) {
            let res = await UserProfilesAPI()
            // console.log('用户信息', res);
            commit('changeUserInfo', res.data)
            // let token = localStorage.getItem['x-auth-token']
            // if (token) { }
        }

    }
}